#ifndef __GEOMETRY_H_
#define __GEOMETRY_H_

#include "Vector3.h"
#include "Triangle.h"

typedef Triangle* SceneTriangleList;
typedef SSEVertex* SceneVertexList;
typedef Vector3* VertexNormalList;

namespace CyberX3D
{
	class SceneGraph;
	class Node;
}

class SoCallbackAction;
class SoPrimitiveVertex;
class SoCoordinate3;
class SoIndexedFaceSet;

enum ModelType {ROBOT_MODEL, OBSTACLE_MODEL};

class ModelInstance
{
public:
	SceneTriangleList trilist;
	SceneVertexList verlist;
	
	unsigned int nVerts;
	unsigned int nTris;
	
	Vector3 bb[2]; // axis-aligned bounding box
	
	bool isInstanced;
	bool boundingBoxGenerated;
	std::string modelFileName;
	
	void* bvh_constru;
	void* obbTree; // pointer to obbtree (on device)
	void* vertexPointer;
	void* triIdxPointer;
	
	unsigned int vbo_Vertex, vbo_TriIndex; // for OPENGL interoperability
	
	ModelType modelType;
	
	ModelInstance();
	
	~ModelInstance();
	
	void destroy();
	
	void calculateAABoundingBox();
	
	int load(const char* fileName, float scalarFactor);
	
	int loadOBJ(const char* fileName, float scalarFactor);
	
	int loadPLY(const char* fileName, float scalarFactor);
	
	int loadTRI(const char* fileName, float scalarFactor);
	
	int loadTRI2(const char* fileName, float scalarFactor);
	
	int loadVRML(const char *fileName, float scalarFactor);
	
	int loadIV(const char* fileName, float scalarFactor);
	
	int loadSTLA(const char* fileName, float scalarFactor);
	
	int loadSTLB(const char* fileName, float scalarFactor);
	
	int makeBox(float a, float b, float c);
	int makeCylinder(float r, float h, int tot = 32);
	int makeSphere(float r, int seg = 32, int ring = 32);
	
	void saveOBJ(const char* fileName);
	
private:	                      
	void traverseVRMLSceneGraph(CyberX3D::SceneGraph *sceneGraph, CyberX3D::Node *firstNode, unsigned int level);
 
};


#endif
